#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;
class Solution7
{
public:
    int largestSumAfterKNegations(vector<int>& nums, int k)
    {
        priority_queue<int, vector<int>, greater<int>> heap;
        for (auto e : nums) heap.push(e);
        while (k)
        {
            if (heap.top() >= 0 && k % 2 == 0) break;
            int tmp = heap.top();
            heap.pop();
            heap.push(-tmp);
            k--;
        }
        int ret = 0;
        while (heap.size())
        {
            ret += heap.top();
            heap.pop();
        }
        return ret;
    }
};
class Solution
{
public:
    vector<int> advantageCount(vector<int>& nums1, vector<int>& nums2)
    {
        int n = nums1.size();
        vector<int> v;
        for (int i = 0;i < n;i++) v.push_back(i);
        sort(v.begin(), v.end(), [&](int i, int j) {
            return nums1[i] < nums1[j];
            });
            sort(nums2.begin(), nums2.end());
            vector<int> ret(n);
            int pptr = 0, tptr=n-1,ptr2 = 0;
            while (ptr2 < n)
            {
                if (nums2[ptr2] < nums1[v[pptr]])
                {
                    ret[v[tptr]] = nums2[ptr2];
                    tptr--;
                }
                else
                {
                    ret[v[pptr]] = nums2[ptr2];
                    pptr++;
                }
                ptr2++;
            }
            return ret;
    }
};
int main()
{
    vector<int> v1 = { 2,7,11,15 };
    vector<int> v2 = { 1,10,4,11 };
    Solution().advantageCount(v1, v2);
	return 0;
}